﻿using SwenAssigment.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SwenAssigment
{
    public partial class GuestUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sss = (string)Session["gid"];
            if (Session["gid"] != null)
            {
                if (Label1.Text == "Label")
                {
                    string line = "select * from guest where Guest_ID='" + sss + "'";
                    RADcon con = new RADcon();
                    string[] s = con.grestrieveone(line);
                    Label1.Text = s[0];
                    Label2.Text = s[1];
                    Label3.Text = s[2];
                    TextBox1.Text = s[3];
                    TextBox2.Text = s[4];
                    TextBox3.Text = s[5];
                    Label4.Text = s[6];
                    //Session["gid"] = null;
                    if (Page.Request.UrlReferrer.LocalPath == "/GuestDetail.aspx")
                    {

                    }
                    else
                    {
                        Response.Redirect("RoomAvalibility.aspx");
                    }
                }
            }
            else
            {
                Response.Redirect("RoomAvalibility.aspx");
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            try
            {
                RADcon con = new RADcon();
                int id = int.Parse(Label1.Text);
                int contact = int.Parse(TextBox1.Text);
                string email = TextBox2.Text;
                string address = TextBox3.Text;
                bool b = con.gupdate(id, contact, email, address);
                if (b == true)
                {
                    Session["mystat"] = "Guest Updated";
                    Response.Redirect("RoomAvalibility.aspx");
                }
                else
                {
                    Label5.Visible = true;
                }
            }
            catch
            {
                Label5.Visible = true;
            }
        }
    }
}